#include <stdio.h>
#include <pthread.h>

#define N   2

char **ptr;     /* global variable */

void *thread(void *arg)
{
    int myid = (int)arg;
    static int cnt = 0;
    printf("[%d]: %s (cnt=%d)\n", myid, ptr[myid], ++cnt);
    printf("myid at thread[%d] %p\n", myid, &myid);
    printf("cnt at thread[%d] %p\n", myid, &cnt);
    return NULL;
}

int main(int argc, char const* argv[])
{
    int i;
    pthread_t tid;

    char *msgs[N] = 
    {
        "Hello from foo",
        "Hello from bar"
    };

    ptr = msgs;
    printf("msgs at main thread %p\n", &msgs);
    for (i = 0; i < N; i++) {
        pthread_create(&tid, NULL, thread, (void *)i);
    }

    pthread_exit(NULL);
}
